package com.example.administrator.swiperefreshlayoutdemo;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener{

    @Bind(R.id.swip_container)
    SwipeRefreshLayout swipContainer;
    @Bind(R.id.tv_refresh)
    TextView tvRefresh;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        swipContainer.setOnRefreshListener(this);
        //设置刷新时动画的颜色，可设置4个
        swipContainer.setColorSchemeResources(android.R.color.holo_blue_light,
                android.R.color.holo_red_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_green_light);
    }

    @Override
    public void onRefresh() {
           tvRefresh.setText("正在刷新");
           new Handler().postDelayed(new Runnable() {
               @Override
               public void run() {
                   tvRefresh.setText("刷新完成");
                   swipContainer.setRefreshing(false);
               }
           },5000);
    }
}
